<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间序列分析 - 河域分割系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">河域分割系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('dashboard') }}">仪表板</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.my_data') }}">我的数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.upload') }}">上传数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="{{ url_for('analysis.time_series_analysis') }}">时间分析</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> {{ current_user.username }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="#">个人资料</a></li>
                            <li><a class="dropdown-item" href="#">设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">退出登录</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <div class="container my-4">
        <div class="row mb-4">
            <div class="col-md-8">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{{ url_for('data.my_data') }}">我的数据</a></li>
                        <li class="breadcrumb-item active">时间序列分析</li>
                    </ol>
                </nav>
                <h2>水域时间序列分析</h2>
                <p class="text-muted">分析水域面积随时间的变化趋势</p>
            </div>
            <div class="col-md-4 text-end">
                <a href="{{ url_for('data.my_data') }}" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-left"></i> 返回我的数据
                </a>
            </div>
        </div>

        <!-- 时间序列图表 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">水域面积时间变化趋势</h5>
                    </div>
                    <div class="card-body text-center">
                        <img src="{{ chart_url }}" class="img-fluid" alt="时间序列图表" style="max-width: 100%;">
                    </div>
                </div>
            </div>
        </div>

        <!-- 数据表格 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">详细数据</h5>
                    </div>
                    <div class="card-body">
                        <ul class="nav nav-tabs" id="myTab" role="tablist">
                            {% if model_predictions.unet %}
                            <li class="nav-item" role="presentation">
                                <button class="nav-link active" id="unet-tab" data-bs-toggle="tab" data-bs-target="#unet" type="button" role="tab" aria-controls="unet" aria-selected="true">U-Net 模型</button>
                            </li>
                            {% endif %}
                            {% if model_predictions.u2net %}
                            <li class="nav-item" role="presentation">
                                <button class="nav-link {% if not model_predictions.unet %}active{% endif %}" id="u2net-tab" data-bs-toggle="tab" data-bs-target="#u2net" type="button" role="tab" aria-controls="u2net" aria-selected="{% if not model_predictions.unet %}true{% else %}false{% endif %}">U2-Net 模型</button>
                            </li>
                            {% endif %}
                            {% if model_predictions.mndwi %}
                            <li class="nav-item" role="presentation">
                                <button class="nav-link {% if not model_predictions.unet and not model_predictions.u2net %}active{% endif %}" id="mndwi-tab" data-bs-toggle="tab" data-bs-target="#mndwi" type="button" role="tab" aria-controls="mndwi" aria-selected="{% if not model_predictions.unet and not model_predictions.u2net %}true{% else %}false{% endif %}">MNDWI 方法</button>
                            </li>
                            {% endif %}
                        </ul>
                        <div class="tab-content" id="myTabContent">
                            {% if model_predictions.unet %}
                            <div class="tab-pane fade show active" id="unet" role="tabpanel" aria-labelledby="unet-tab">
                                <div class="table-responsive mt-3">
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th>日期</th>
                                                <th>水域面积比例</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {% for pred in model_predictions.unet %}
                                            <tr>
                                                <td>{{ pred.date }}</td>
                                                <td>{{ "%.2f"|format(pred.water_area * 100) }}%</td>
                                                <td>
                                                    <a href="{{ url_for('prediction.view_result', prediction_id=pred.id) }}" class="btn btn-sm btn-primary">查看</a>
                                                </td>
                                            </tr>
                                            {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            {% endif %}
                            {% if model_predictions.u2net %}
                            <div class="tab-pane fade {% if not model_predictions.unet %}show active{% endif %}" id="u2net" role="tabpanel" aria-labelledby="u2net-tab">
                                <div class="table-responsive mt-3">
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th>日期</th>
                                                <th>水域面积比例</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {% for pred in model_predictions.u2net %}
                                            <tr>
                                                <td>{{ pred.date }}</td>
                                                <td>{{ "%.2f"|format(pred.water_area * 100) }}%</td>
                                                <td>
                                                    <a href="{{ url_for('prediction.view_result', prediction_id=pred.id) }}" class="btn btn-sm btn-primary">查看</a>
                                                </td>
                                            </tr>
                                            {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            {% endif %}
                            {% if model_predictions.mndwi %}
                            <div class="tab-pane fade {% if not model_predictions.unet and not model_predictions.u2net %}show active{% endif %}" id="mndwi" role="tabpanel" aria-labelledby="mndwi-tab">
                                <div class="table-responsive mt-3">
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th>日期</th>
                                                <th>水域面积比例</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {% for pred in model_predictions.mndwi %}
                                            <tr>
                                                <td>{{ pred.date }}</td>
                                                <td>{{ "%.2f"|format(pred.water_area * 100) }}%</td>
                                                <td>
                                                    <a href="{{ url_for('prediction.view_result', prediction_id=pred.id) }}" class="btn btn-sm btn-primary">查看</a>
                                                </td>
                                            </tr>
                                            {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 分析结论 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">分析结论</h5>
                    </div>
                    <div class="card-body">
                        <div class="alert alert-info">
                            <h6><i class="bi bi-info-circle me-2"></i>水域变化趋势</h6>
                            <p>根据收集的数据分析，您的研究区域水域面积呈现以下趋势：</p>
                            {% set has_data = false %}
                            {% for model, preds in model_predictions.items() %}
                                {% if preds|length > 1 %}
                                    {% set has_data = true %}
                                    {% set first = preds[0].water_area %}
                                    {% set last = preds[-1].water_area %}
                                    {% if last > first %}
                                        <p>
                                            基于{{ model }}模型的分析显示，水域面积有<strong class="text-success">增长</strong>趋势，
                                            从{{ "%.2f"|format(first * 100) }}%增长到{{ "%.2f"|format(last * 100) }}%，
                                            增长了{{ "%.2f"|format((last - first) * 100) }}个百分点。
                                        </p>
                                    {% elif last < first %}
                                        <p>
                                            基于{{ model }}模型的分析显示，水域面积有<strong class="text-danger">下降</strong>趋势，
                                            从{{ "%.2f"|format(first * 100) }}%下降到{{ "%.2f"|format(last * 100) }}%，
                                            下降了{{ "%.2f"|format((first - last) * 100) }}个百分点。
                                        </p>
                                    {% else %}
                                        <p>
                                            基于{{ model }}模型的分析显示，水域面积<strong>保持稳定</strong>，
                                            始终保持在{{ "%.2f"|format(first * 100) }}%左右。
                                        </p>
                                    {% endif %}
                                {% endif %}
                            {% endfor %}
                            {% if not has_data %}
                                <p>需要更多的时间点数据才能进行趋势分析。请尝试对同一区域的不同时间点图像进行预测。</p>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 操作按钮 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="d-flex justify-content-between">
                    <a href="{{ url_for('data.my_data') }}" class="btn btn-primary">
                        <i class="bi bi-images"></i> 添加更多数据
                    </a>
                    <a href="#" class="btn btn-outline-secondary">
                        <i class="bi bi-download"></i> 导出分析报告
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-4 mt-5">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h5>河域分割系统</h5>
                    <p>基于深度学习的河域分割与分析平台</p>
                </div>
                <div class="col-md-3">
                    <h5>链接</h5>
                    <ul class="list-unstyled">
                        <li><a href="{{ url_for('index') }}" class="text-white">首页</a></li>
                        <li><a href="{{ url_for('dashboard') }}" class="text-white">仪表板</a></li>
                        <li><a href="{{ url_for('data.my_data') }}" class="text-white">我的数据</a></li>
                    </ul>
                </div>
                <div class="col-md-3">
                    <h5>账户</h5>
                    <ul class="list-unstyled">
                        <li><a href="#" class="text-white">个人资料</a></li>
                        <li><a href="#" class="text-white">设置</a></li>
                        <li><a href="{{ url_for('auth.logout') }}" class="text-white">退出登录</a></li>
                    </ul>
                </div>
            </div>
            <hr>
            <div class="text-center">
                <p>&copy; 2023 河域分割系统. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html> 